﻿using System;
using System.ComponentModel;
using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for SummaryForm.xaml
    /// </summary>
    /// 
    public partial class YGRONAV95 : DocumentBase
    {
        #region-------------Properties-----------------------
        #region ==IsAK02===========
        public static readonly DependencyProperty IsAK02Property = DependencyProperty.Register("IsAK02",
            typeof(bool), typeof(YGRONAV95),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsAK02Changed));
        public bool IsAK02
        {
            get
            {
                return (bool)GetValue(IsAK02Property);
            }
            set
            {
                SetValue(IsAK02Property, value);
            }
        }
        private static void OnIsAK02Changed(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as YGRONAV95;
            if (src != null)
            {
                src.IsAK02 = (bool)e.NewValue;
            }
        }

        #endregion
        #region ==IsVK===========
        public static readonly DependencyProperty IsVKProperty = DependencyProperty.Register("IsVK",
            typeof(bool), typeof(YGRONAV95),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsVKChanged));
        public bool IsVK
        {
            get
            {
                return (bool)GetValue(IsVKProperty);
            }
            set
            {
                SetValue(IsVKProperty, value);
            }
        }
        private static void OnIsVKChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as YGRONAV95;
            if (src != null)
            {
                src.IsVK = (bool)e.NewValue;
            }
        }

        #endregion
        #region ==IsAB===========
        public static readonly DependencyProperty IsABProperty = DependencyProperty.Register("IsAB",
            typeof(bool), typeof(YGRONAV95),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsABChanged));
        public bool IsAB
        {
            get
            {
                return (bool)GetValue(IsABProperty);
            }
            set
            {
                SetValue(IsABProperty, value);
            }
        }
        private static void OnIsABChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as YGRONAV95;
            if (src != null)
            {
                src.IsAB = (bool)e.NewValue;
            }
        }

        #endregion
        #region ==IsYNZ===========
        public static readonly DependencyProperty IsYNZProperty = DependencyProperty.Register("IsYNZ",
            typeof(bool), typeof(YGRONAV95),
            new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsYNZChanged));
        public bool IsYNZ
        {
            get
            {
                return (bool)GetValue(IsYNZProperty);
            }
            set
            {
                SetValue(IsYNZProperty, value);
            }
        }
        private static void OnIsYNZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as YGRONAV95;
            if (src != null)
            {
                src.IsYNZ = (bool)e.NewValue;
            }
        }

        #endregion
        
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        public INTEXDBC INTEXDBC
        {
            get
            {
                return app.INTEXDBC;
            }
        }
        public INTEXBL INTEXBL
        {
            get
            {
                return app.INTEXBL;
            }
        }
        VYGRONAV95 vm;  
        public YGRONAV95()
        {
            vm = new VYGRONAV95();
            DataContext = vm;
            InitializeComponent(); 
            this.Name = "计划编排";      
            vm.LoadEnv();
            IsAB = true;
        }
        #endregion
    
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
           
            EventDispatcher.Instance.OnStatusChange += Instance_OnStatusChange;
            txtMessage.Visibility = Visibility.Collapsed;
        }
        void Instance_OnStatusChange(object sender, StatusEventArgs e)
        {
            MessageInfo msg = ((StatusEventArgs)e).Info;
            string Message = msg.Details.Trim();
            if (Message != "")
            {
                txtMessage.Text = msg.Details;
                if (Message.Contains("YGRAV95"))
                {
                    txtMessage.Visibility = Visibility.Visible;
                }
                if (Message.Contains("YGRAV95启动"))
                {
                    txtMessage.Visibility = Visibility.Visible;
                }
                if (Message.Contains("YGRAV95完成"))
                {  
                    vwVKP.IsInComositon = false;
                    vm.ReArrangeVKPOS();
                    txtMessage.Visibility = Visibility.Collapsed; 
                }
                if (Message.Contains("YGRAV95异常终止"))
                {
                    txtMessage.Visibility = Visibility.Collapsed;
                }

            }
        }
        private void btnLoadVKPList_Click(object sender, RoutedEventArgs e)
        {
            vm.LoadVKPList();
        }
        private void btnGotoPlan_Click(object sender, RoutedEventArgs e)
        {
            ABCommand(null, null);
            vwVKP.KRS = vm.KRS;
            vwVKP.LFD = vm.LFD;
            vwVKP.Query();
        }  
        private void ReSetTab()
        {
            IsAK02 = false;
            IsAB = false;
            IsVK = false;
            IsYNZ = false;
        }
        private void AK02Command(object sender, RoutedEventArgs e)
        {
            ReSetTab();
            IsAK02 = true;
            MessageInfo msg = new MessageInfo();
            msg.Sender = this.RUNID;
            msg.MSGTYPE = "STAK02";
            msg.ACTION = "STAK02";
            msg.KRS = "  ";
            msg.LFD = "0400";
            msg.POS = "XS      ";
            VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", null, "", msg);
        }
        private void VKCommand(object sender, RoutedEventArgs e)
        {
            ReSetTab();
            IsVK = true;
           
        }
        private void ABCommand(object sender, RoutedEventArgs e)
        {
            ReSetTab();
            IsAB = true; 
        }

        private void YNZCommand(object sender, RoutedEventArgs e)
        {
            ReSetTab();
            IsYNZ = true;
            MessageInfo msg = new MessageInfo();
            msg.Sender = this.RUNID;
            msg.MSGTYPE = "STAK02YN";
            msg.ACTION = "STAK02YN";
            msg.KRS = "  ";
            msg.LFD = "0400";
            msg.POS = "XS      ";
            VICC_WFEVENTS.SVWF.CheckEvents("UIMESSAGE", null, "", msg);
        }
    }
}
